import {PureComponent} from "react";
import {connect} from "react-redux";
import {addNumberAction, subNumberAction} from "../store/modules/count";

class Profile extends PureComponent {

    addNum(num) {
        this.props.addNumber(num)
    }

    subNum(num) {
        this.props.subNumber(num)
    }

    render() {
        const {count} = this.props;
        return (
            <div>
                <div>profile组件count:{count} </div>
                <button onClick={() => this.addNum(2)}>+2</button>
                <button onClick={() => this.subNum(2)}>-2</button>
            </div>
        )
    }
}

const mapStateToProps = (state) => ({count: state.count.count})
const mapDispatchToProps = (dispatch) => ({
    addNumber: (num) => dispatch(addNumberAction(num)),
    subNumber: (num) => dispatch(subNumberAction(num))
})
export default connect(mapStateToProps, mapDispatchToProps)(Profile)